﻿using System;
using System.Web.UI;
using EmptyWallGallery.Core;
using Microsoft.VisualBasic;

namespace EmptyWallGallery.FrontEnd.inside.Editor.Products
{
    public partial class EditAlbum : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
            if (Request.QueryString["Id"] == null) Response.Redirect("Album.aspx");
            if (!Core.Utilities.Common.Instance.IsNumeric(Request.QueryString["Id"])) Response.Redirect("Album.aspx");

            var album = Core.BLL.Album.Instance.GetById(Convert.ToInt32(Request.QueryString["Id"]));
            if (album == null)
            {
                Response.Redirect("Album.aspx");
            }
            else
            {
                txtAlbumName.Text = album.AlbumName;
                txtDescription.Text = album.AlbumDesc;
                createDate.InnerHtml = WriteCreateDate(album.CreateDate);
                viewcount.InnerHtml = album.ViewCount.ToString();
            }
        }

        protected void BtnUpdateClick(object sender, EventArgs e)
        {
            var albumName = Core.Utilities.Common.Instance.NoHtml(txtAlbumName.Text);
            var albumDesc = Core.Utilities.Common.Instance.NoHtml(txtDescription.Text);

            Core.BLL.Album.Instance.Update(albumName, albumDesc, "", Convert.ToInt32(Request.QueryString["Id"]));

            Response.Redirect("Album.aspx");
        }

        protected string WriteCreateDate(DateTime createdDate)
        {
            return Strings.Format(createdDate.AddHours(Configs.TimeLine),
                                  "dd-MM-yyyy HH:mm tt");
        }
    }
}